package cn.buk.qms.captcha;

import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * User: william
 * Date: 14-7-7
 * Time: 上午12:29
 * To change this template use File | Settings | File Templates.
 * @author yfdai
 */
public class RandomGenerator {
    private final static String RANGE = "0123456789abcdefghijklmnopqrstuvwxyz";
    private final static String NUMBER_RANGE = "01256789";

    public static synchronized String getRandomString()
    {
        Random random = new Random();

        StringBuffer result = new StringBuffer();

        for ( int i = 0; i < 8; i++ )
        {
            result.append( RANGE.charAt( random.nextInt( RANGE.length() ) ) );
        }

        return result.toString();
    }

    public static synchronized String getRandomNumberString()
    {
        Random random = new Random();

        StringBuffer result = new StringBuffer();

        for ( int i = 0; i < 6; i++ )
        {
            result.append( NUMBER_RANGE.charAt( random.nextInt( NUMBER_RANGE.length() ) ) );
        }

        return result.toString();
    }
}
